library(Zelig)
library(foreign)

data1fd <- read.dta("dataFD_1.dta")
data2fd <- read.dta("dataFD_2.dta")
data3fd <- read.dta("dataFD_3.dta")
data4fd <- read.dta("dataFD_4.dta")
data5fd <- read.dta("dataFD_5.dta")

###################################Cross Tabs
treated<-subset(data1fd,art8==1)
control<-subset(data1fd,art8==0)

table(treated$fd_restrict,treated$l_leftshift_exc)
table(control$fd_restrict,control$l_leftshift_exc)

table(treated$fd_restrict,treated$l_leftshift_inc)
table(control$fd_restrict,control$l_leftshift_inc)

table(treated$fd_restrict,treated$l_leftshift_exc_leg)
table(control$fd_restrict,control$l_leftshift_exc_leg)

table(treated$fd_restrict,treated$l_leftshift_inc_leg)
table(control$fd_restrict,control$l_leftshift_inc_leg)


########Ordered Logit Tests on Leftshift Variables

##Exclusive Leftshifts
z.out<- zelig(as.factor(fd_restrict) ~ leftshift_exc +
fd_flexible + fd_gnpcap + fd_regnorm + 
fd_gdpgrow + fd_resgdp + fd_bopgdp + fd_useimfcr + fd_surveil + fd_univers + 
fd_tradedep + fd_resvol + fd_totvol + fd_military + fd_termlim + fd_parli +
fd_lastrest + fd_lastrest2 + fd_lastrest3, 
data=mi(data1fd,data2fd,data3fd,data4fd,data5fd),
model="ologit",
)
summary(z.out)

##Inclusive Leftshifts
z.out2<- zelig(as.factor(fd_restrict) ~ leftshift_inc + 
fd_flexible + fd_gnpcap + fd_regnorm + 
fd_gdpgrow + fd_resgdp + fd_bopgdp + fd_useimfcr + fd_surveil + fd_univers + 
fd_tradedep + fd_resvol + fd_totvol + fd_military + fd_termlim + fd_parli +
fd_lastrest + fd_lastrest2 + fd_lastrest3, 
data=mi(data1fd,data2fd,data3fd,data4fd,data5fd),
model="ologit",
)
summary(z.out2)

##Exclusive Leftshifts with Legislative
z.out3<- zelig(as.factor(fd_restrict) ~ leftshift_exc_leg + 
fd_flexible + fd_gnpcap + fd_regnorm + 
fd_gdpgrow + fd_resgdp + fd_bopgdp + fd_useimfcr + fd_surveil + fd_univers + 
fd_tradedep + fd_resvol + fd_totvol + fd_military + fd_termlim + fd_parli +
fd_lastrest + fd_lastrest2 + fd_lastrest3, 
data=mi(data1fd,data2fd,data3fd,data4fd,data5fd),
model="ologit",
)
summary(z.out3)

##Inclusive Leftshifts with Legislative
z.out4<- zelig(as.factor(fd_restrict) ~ leftshift_inc_leg +
fd_flexible + fd_gnpcap + fd_regnorm + 
fd_gdpgrow + fd_resgdp + fd_bopgdp + fd_useimfcr + fd_surveil + fd_univers + 
fd_tradedep + fd_resvol + fd_totvol + fd_military + fd_termlim + fd_parli +
fd_lastrest + fd_lastrest2 + fd_lastrest3, 
data=mi(data1fd,data2fd,data3fd,data4fd,data5fd),
model="ologit",
)
summary(z.out4)

########################Leftward Shifts Specification (Mentioned But Not Presented in the Paper)
##Tests are on Subsets 

##Subsetting Code
data1fdIL<-subset(data1fd,l_leftshift_inc_leg==1)
data1fdI<-subset(data1fd,l_leftshift_inc==1)
data1fdEL<-subset(data1fd,l_leftshift_exc_leg==1)
data1fdE<-subset(data1fd,l_leftshift_exc==1)

data2fdIL<-subset(data2fd,l_leftshift_inc_leg==1)
data2fdI<-subset(data2fd,l_leftshift_inc==1)
data2fdEL<-subset(data2fd,l_leftshift_exc_leg==1)
data2fdE<-subset(data2fd,l_leftshift_exc==1)

data3fdIL<-subset(data3fd,l_leftshift_inc_leg==1)
data3fdI<-subset(data3fd,l_leftshift_inc==1)
data3fdEL<-subset(data3fd,l_leftshift_exc_leg==1)
data3fdE<-subset(data3fd,l_leftshift_exc==1)

data4fdIL<-subset(data4fd,l_leftshift_inc_leg==1)
data4fdI<-subset(data4fd,l_leftshift_inc==1)
data4fdEL<-subset(data4fd,l_leftshift_exc_leg==1)
data4fdE<-subset(data4fd,l_leftshift_exc==1)

data5fdIL<-subset(data5fd,l_leftshift_inc_leg==1)
data5fdI<-subset(data5fd,l_leftshift_inc==1)
data5fdEL<-subset(data5fd,l_leftshift_exc_leg==1)
data5fdE<-subset(data5fd,l_leftshift_exc==1)

##Rightshifts
data1fdRIL<-subset(data1fd,l_rightshift_inc_leg==1)
data1fdRI<-subset(data1fd,l_rightshift_inc==1)
data1fdREL<-subset(data1fd,l_rightshift_exc_leg==1)
data1fdRE<-subset(data1fd,l_rightshift_exc==1)

data2fdRIL<-subset(data2fd,l_rightshift_inc_leg==1)
data2fdRI<-subset(data2fd,l_rightshift_inc==1)
data2fdREL<-subset(data2fd,l_rightshift_exc_leg==1)
data2fdRE<-subset(data2fd,l_rightshift_exc==1)

data3fdRIL<-subset(data3fd,l_rightshift_inc_leg==1)
data3fdRI<-subset(data3fd,l_rightshift_inc==1)
data3fdREL<-subset(data3fd,l_rightshift_exc_leg==1)
data3fdRE<-subset(data3fd,l_rightshift_exc==1)

data4fdRIL<-subset(data4fd,l_rightshift_inc_leg==1)
data4fdRI<-subset(data4fd,l_rightshift_inc==1)
data4fdREL<-subset(data4fd,l_rightshift_exc_leg==1)
data4fdRE<-subset(data4fd,l_rightshift_exc==1)

data5fdRIL<-subset(data5fd,l_rightshift_inc_leg==1)
data5fdRI<-subset(data5fd,l_rightshift_inc==1)
data5fdREL<-subset(data5fd,l_rightshift_exc_leg==1)
data5fdRE<-subset(data5fd,l_rightshift_exc==1)

##Inclusive Leftshifts
z.out<- zelig(fd_restrict ~ l2_art8 + fd_flexible + fd_gnpcap + fd_regnorm + 
fd_gdpgrow + fd_resgdp + fd_bopgdp + fd_useimfcr + fd_surveil + fd_univers + 
fd_tradedep + fd_resvol + fd_totvol + fd_military + fd_termlim + fd_parli, 
data=mi(data1fdI,data2fdI,data3fdI,data4fdI,data5fdI),
model="ls",
)
summary(z.out)

##Exclusive Leftshifts
z.out2<- zelig(fd_restrict ~ l2_art8 + fd_flexible + fd_gnpcap + fd_regnorm + 
fd_gdpgrow + fd_resgdp + fd_bopgdp + fd_useimfcr + fd_surveil + fd_univers + 
fd_tradedep + fd_resvol + fd_totvol + fd_military + fd_termlim + fd_parli, 
data=mi(data1fdE,data2fdE,data3fdE,data4fdE,data5fdE),
model="ls",
)
summary(z.out2)

##Inclusive Leftshifts with Legislative
z.out3<- zelig(fd_restrict ~ l2_art8 + fd_flexible + fd_gnpcap + fd_regnorm + 
fd_gdpgrow + fd_resgdp + fd_bopgdp + fd_useimfcr + fd_surveil + fd_univers + 
fd_tradedep + fd_resvol + fd_totvol + fd_military + fd_termlim + fd_parli, 
data=mi(data1fdIL,data2fdIL,data3fdIL,data4fdIL,data5fdIL),
model="ls",
)
summary(z.out3)

##Exclusive Leftshifts with Legislative
z.out4<- zelig(fd_restrict ~ l2_art8 + fd_flexible + fd_gnpcap + fd_regnorm + 
fd_gdpgrow + fd_resgdp + fd_bopgdp + fd_useimfcr + fd_surveil + fd_univers + 
fd_tradedep + fd_resvol + fd_totvol + fd_military + fd_termlim + fd_parli, 
data=mi(data1fdEL,data2fdEL,data3fdEL,data4fdEL,data5fdEL),
model="ls",
)
summary(z.out4)





